foreach loop in python

36

# 'foreach' in python is done using 'for'
for val in array:
    print(val)
// PHP:
foreach ($array as $val) {
    print($val);
}

// C#
foreach (String val in array) {
    console.writeline(val);
}

// Python
for val in array:
    print(val)
names = ['tom', 'john', 'simon']

namesCapitalized = [capitalize(n) for n in names]

Comments

Submit
0 Comments